const db = require('./index');

module.exports = {
    findProduct: async (user_id, product_id) => {
        const sql = ` select * from shoppingCart where user_id = ? and product_id = ? `;
        return await db.query(sql, [user_id, product_id]);
    },
    updateCart: async (num, user_id, product_id) => {
        const sql = ` UPDATE shoppingcart SET num = ? WHERE user_id = ? AND product_id = ? `;
        return await db.query(sql, [num, user_id, product_id]);
    },
    addCart: async (user_id, product_id) => {
        const sql = `insert into shoppingCart values(null,?,?,1)`;
        return await db.query(sql, [user_id, product_id]);
    },
    getCart: async user_id => {
        const sql = ` select * from shoppingCart where user_id = ? `;
        return db.query(sql, user_id);
    },
    deleteProduct: async (user_id, product_id) => {
        const sql = ` delete from shoppingCart where user_id = ? and product_id = ? `;
        return db.query(sql, [user_id, product_id])
    },
    deleteCart: async (user_id, product_id) => {
        const sql = ` delete from shoppingCart where user_id = ? and product_id = ? `;
        return db.query(sql, [user_id, product_id])
    }
}